﻿/// <reference path="//Microsoft.WinJS.0.6/js/base.js" /> 
/// <reference path="//Microsoft.WinJS.0.6/js/ui.js" /> 
(function () {
    "use strict";

    var mobileService = new WindowsAzure.MobileServiceClient("https://stickeralbum.azure-mobile.net/", "kykxDEEXBFMtYzPyBJdwTAHlXtwiNl95");

    //Function for setting an image in the img tag
    //idImage - the id of the image tag
    //item - the Player object that contains the picture
    function setImage(idImage, item) {
        var pic = document.getElementById(idImage);
        pic.src = item.slika;
    };

    //A get random player function
    //Used for getting the sticker packet
    //idImage - the id of the image tag where the picture should be set
    function getRandomPicture(callback) {
        var rand = Math.floor(Math.random() * 197);

        try {
            mobileService.getTable("Player").where({ id: rand }).read().done(function (result) {
                callback(result[0]);
            });
        } catch (exception) {
            var msg = new Windows.UI.Popups.MessageDialog("This application requires an internet connection");
            msg.showAsync();
        }
    }

    var publicMembers = {
        setImage: setImage,
        getRandomPicture: getRandomPicture
    };

    WinJS.Namespace.define("fullData", publicMembers);
})();